package com.athbsd;

import com.athbsd.exer4.Student;

import java.util.HashSet;

/**
 * Date:2025/2/24
 * Author：zhouzhou
 * Description:
 */
public class HashSet_add {
    public static void main(String[] args) {
        HashSet set = new HashSet();
        Student s1 = new Student("tom",12);
        Student s2 = new Student("jack",13);
        set.add(s1);
        set.add(s2);
        System.out.println(set);
        {//s1.name已经改成了rose
            s1.setName("rose");
            //拿s1-->rose,12的哈希值去找,找不到原先是 s1-->tom,12
            // 所以没法移除s1.
            set.remove(s1);
        }
        System.out.println(set);
        //此时添加.拿rose,12计算哈希值,会与最开始的tom,12的哈希值比较,--->不同,可以添加.
        set.add(new Student("rose",12));
        //  可以添加, 与最开始的tom,12的哈希值一样,但equals不同
        set.add(new Student("tom",12));
    }
}
